@SET_MAKE@
SUBDIRS= gauche util data srfi uvector threads charconv binary net termios \
         fcntl file sxml syslog dbm mt-random bcrypt digest vport \
         text rfc zlib sparse peg windows tls

.PHONY: $(SUBDIRS)

CONFIG_GENERATED = Makefile Makefile.ext

SHELL       = @SHELL@
prefix      = @prefix@
exec_prefix = @exec_prefix@
bindir      = @bindir@
libdir      = @libdir@
datadir     = @datadir@
datarootdir = @datarootdir@
srcdir      = @srcdir@
VPATH       = $(srcdir)
top_builddir = @top_builddir@
top_srcdir   = @top_srcdir@
GAUCHE_VERSION = @GAUCHE_VERSION@
DESTDIR     =

@CROSS_COMPILING_no@GOSH           = $(top_builddir)/src/gosh -ftest
@CROSS_COMPILING_yes@GOSH           = gosh
GAUCHE_INSTALL = $(GOSH) $(top_srcdir)/src/gauche-install.in -C
TEMPLATE_INST_DIR = $(datadir)/gauche-@GAUCHE_ABI_VERSION@/$(GAUCHE_VERSION)

TEMPLATES = template.Makefile.in template.configure template.configure.ac \
	    template.extension.h template.extension.c \
	    template.extensionlib.stub template.module.scm \
	    template.package.scm template.test.scm

all: $(SUBDIRS)

$(SUBDIRS):
	(cd $@; $(MAKE) default)

uvector: data util

gauche srfi: util uvector charconv

net: gauche srfi

text: uvector srfi charconv

threads bcrypt sxml mt-random digest zlib termios windows: uvector

vport: gauche uvector

tls: vport net

bcrypt: mt-random

dbm : threads

rfc: gauche srfi util

test : check

check:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) check) || exit 1; done

install:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) install) || exit 1; done
	$(GAUCHE_INSTALL) -m 444 -S $(srcdir) $(TEMPLATES) "$(DESTDIR)$(TEMPLATE_INST_DIR)"

uninstall:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) uninstall); done
	for f in $(TEMPLATES); do \
	  rm -f "$(DESTDIR)$(TEMPLATE_INST_DIR)/$$f"; \
	done

clean:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) clean); done
	rm -rf core *~

pre-package:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) GOSH=$(GOSH) pre-package); done

link :
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) link); done

unlink :
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) unlink); done

distclean: clean
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) distclean); done
	rm -rf $(CONFIG_GENERATED)

maintainer-clean: clean
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) maintainer-clean); done
	rm -rf $(CONFIG_GENERATED)

install-check:
	for d in $(SUBDIRS); do (cd $$d; $(MAKE) install-check); done

list-objects:
	@for d in $(SUBDIRS); do (cd $$d; $(MAKE) list-objects); done
